package com.funtl.apache.dubbo.log.mq.consumer;

import com.funtl.apache.dubbo.log.dto.OrderLogDto;
import com.funtl.apache.dubbo.log.mq.message.OrderMessage;
import com.funtl.apache.dubbo.log.service.OrderLogService;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Slf4j
@Service
@RocketMQMessageListener(consumerGroup = "rocketmq-group", topic = "add-order")
public class OrderListener implements RocketMQListener<OrderMessage> {
    @Autowired
    private OrderLogService orderLogDao;

    @Override
    public void onMessage(OrderMessage orderMessage) {
        log.info("收到消息 => {}", orderMessage);
        OrderLogDto logDto = new OrderLogDto();
        logDto.setOrderId(orderMessage.getOrderId());
        logDto.setOrderItemId(orderMessage.getOrderItemId());
        orderLogDao.insert(logDto);
    }
}
